{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from jsonpath import jsonpath\n",
    "import json\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1000, 1000, 1000)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url = 'http://www.officeplus.cn/WebApi/List?cats=PPT&tags=&currentpage=0&pagesize=10000&order=0'\n",
    "res = requests.get(url)\n",
    "json_data = json.loads(res.text)\n",
    "title_list = jsonpath(json_data,'$..Title')\n",
    "page_list = jsonpath(json_data,'$..Page')\n",
    "download_list = jsonpath(json_data,'$..Download')\n",
    "len(title_list),len(page_list),len(download_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>文件名</th>\n",
       "      <th>详情页网址</th>\n",
       "      <th>下载页网址</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>总结报告-行业通用-商务风格-棕色</td>\n",
       "      <td>http://www.officeplus.cn/DetailPage/Get?id=87&amp;...</td>\n",
       "      <td>http://www.officeplus.cn/Download/Get/103787</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>总结报告-行业通用-清新简约-红色</td>\n",
       "      <td>http://www.officeplus.cn/DetailPage/Get?id=86&amp;...</td>\n",
       "      <td>http://www.officeplus.cn/Download/Get/103786</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>总结报告-行业通用-简约风格-黄蓝灰</td>\n",
       "      <td>http://www.officeplus.cn/DetailPage/Get?id=85&amp;...</td>\n",
       "      <td>http://www.officeplus.cn/Download/Get/103785</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>总结报告-行业通用-创意风格-多色</td>\n",
       "      <td>http://www.officeplus.cn/DetailPage/Get?id=84&amp;...</td>\n",
       "      <td>http://www.officeplus.cn/Download/Get/103784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>总结报告-文娱行业-扁平风格-红蓝</td>\n",
       "      <td>http://www.officeplus.cn/DetailPage/Get?id=83&amp;...</td>\n",
       "      <td>http://www.officeplus.cn/Download/Get/103783</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>项目策划-逻辑结构图时间事件线-鲜艳红色</td>\n",
       "      <td>http://www.officeplus.cn/DetailPage/Get?id=33&amp;...</td>\n",
       "      <td>http://www.officeplus.cn/Download/Get/102533</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>项目策划-关系图分类图时间线-浅绿基调</td>\n",
       "      <td>http://www.officeplus.cn/DetailPage/Get?id=32&amp;...</td>\n",
       "      <td>http://www.officeplus.cn/Download/Get/102532</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>产品推广-比例关系层次架构-淡雅浅紫</td>\n",
       "      <td>http://www.officeplus.cn/DetailPage/Get?id=31&amp;...</td>\n",
       "      <td>http://www.officeplus.cn/Download/Get/102531</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>产品推广-组织结构内容分类逻辑图-酒红基调</td>\n",
       "      <td>http://www.officeplus.cn/DetailPage/Get?id=30&amp;...</td>\n",
       "      <td>http://www.officeplus.cn/Download/Get/102530</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>产品推广-结构内容图表-浅蓝浅绿</td>\n",
       "      <td>http://www.officeplus.cn/DetailPage/Get?id=29&amp;...</td>\n",
       "      <td>http://www.officeplus.cn/Download/Get/102529</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                       文件名                                              详情页网址  \\\n",
       "0        总结报告-行业通用-商务风格-棕色  http://www.officeplus.cn/DetailPage/Get?id=87&...   \n",
       "1        总结报告-行业通用-清新简约-红色  http://www.officeplus.cn/DetailPage/Get?id=86&...   \n",
       "2       总结报告-行业通用-简约风格-黄蓝灰  http://www.officeplus.cn/DetailPage/Get?id=85&...   \n",
       "3        总结报告-行业通用-创意风格-多色  http://www.officeplus.cn/DetailPage/Get?id=84&...   \n",
       "4        总结报告-文娱行业-扁平风格-红蓝  http://www.officeplus.cn/DetailPage/Get?id=83&...   \n",
       "..                     ...                                                ...   \n",
       "995   项目策划-逻辑结构图时间事件线-鲜艳红色  http://www.officeplus.cn/DetailPage/Get?id=33&...   \n",
       "996    项目策划-关系图分类图时间线-浅绿基调  http://www.officeplus.cn/DetailPage/Get?id=32&...   \n",
       "997     产品推广-比例关系层次架构-淡雅浅紫  http://www.officeplus.cn/DetailPage/Get?id=31&...   \n",
       "998  产品推广-组织结构内容分类逻辑图-酒红基调  http://www.officeplus.cn/DetailPage/Get?id=30&...   \n",
       "999       产品推广-结构内容图表-浅蓝浅绿  http://www.officeplus.cn/DetailPage/Get?id=29&...   \n",
       "\n",
       "                                            下载页网址  \n",
       "0    http://www.officeplus.cn/Download/Get/103787  \n",
       "1    http://www.officeplus.cn/Download/Get/103786  \n",
       "2    http://www.officeplus.cn/Download/Get/103785  \n",
       "3    http://www.officeplus.cn/Download/Get/103784  \n",
       "4    http://www.officeplus.cn/Download/Get/103783  \n",
       "..                                            ...  \n",
       "995  http://www.officeplus.cn/Download/Get/102533  \n",
       "996  http://www.officeplus.cn/Download/Get/102532  \n",
       "997  http://www.officeplus.cn/Download/Get/102531  \n",
       "998  http://www.officeplus.cn/Download/Get/102530  \n",
       "999  http://www.officeplus.cn/Download/Get/102529  \n",
       "\n",
       "[1000 rows x 3 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_dict = {'文件名':title_list,'详情页网址':page_list,'下载页网址':download_list}\n",
    "df = pd.DataFrame(df_dict)\n",
    "df['详情页网址'] = df['详情页网址'].map(lambda x:'http://www.officeplus.cn' + str(x))\n",
    "df['下载页网址'] = df['下载页网址'].map(lambda x:'http://www.officeplus.cn' + str(x))\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "清单保存完成！！\n"
     ]
    }
   ],
   "source": [
    "df.to_excel('./officeplus网站PPT模板网页链接清单.xlsx',sheet_name='ppt',index=False)\n",
    "print('清单保存完成！！')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
